<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>学生管理</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            margin: 0;
            padding: 20px;
        }
        .container {
            background-color: #fff;
            padding: 30px;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            max-width: 900px;
            margin: 20px auto;
        }
        h1 {
            color: #333;
            text-align: center;
            margin-bottom: 30px;
        }
        .message.success {
            color: green;
            background-color: #e6ffe6;
            border: 1px solid green;
            padding: 10px;
            border-radius: 4px;
            margin-bottom: 15px;
        }
        .message.error {
            color: red;
            background-color: #ffe6e6;
            border: 1px solid red;
            padding: 10px;
            border-radius: 4px;
            margin-bottom: 15px;
        }
        .button-group {
            margin-bottom: 20px;
            text-align: right;
        }
        .button-group a {
            background-color: #007bff;
            color: white;
            padding: 10px 15px;
            border-radius: 4px;
            text-decoration: none;
            font-size: 15px;
            margin-left: 10px;
        }
        .button-group a:hover {
            background-color: #0056b3;
        }
        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 20px;
        }
        th, td {
            border: 1px solid #ddd;
            padding: 10px;
            text-align: left;
        }
        th {
            background-color: #f2f2f2;
            color: #333;
        }
        .actions a {
            margin-right: 10px;
            color: #007bff;
            text-decoration: none;
        }
        .actions a:hover {
            text-decoration: underline;
        }
        .delete-form {
            display: inline;
        }
        .delete-form button {
            background: none;
            border: none;
            color: #dc3545;
            cursor: pointer;
            font-size: 1em;
            padding: 0;
            text-decoration: none;
        }
        .delete-form button:hover {
            text-decoration: underline;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>学生管理</h1>

        <div th:if="${successMessage}" class="message success">
            <p th:text="${successMessage}"></p>
        </div>
        <div th:if="${errorMessage}" class="message error">
            <p th:text="${errorMessage}"></p>
        </div>

        <div class="button-group">
            <a th:href="@{/students/add}">添加学生</a>
            <a th:href="@{/index}">返回首页</a>
        </div>

        <table>
            <thead>
                <tr>
                    <th>ID</th>
                    <th>学号</th>
                    <th>姓名</th>
                    <th>年龄</th>
                    <th>性别</th>
                    <th>专业</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                <tr th:each="student : ${students}">
                    <td th:text="${student.id}"></td>
                    <td th:text="${student.studentId}"></td>
                    <td th:text="${student.name}"></td>
                    <td th:text="${student.age}"></td>
                    <td th:text="${student.gender}"></td>
                    <td th:text="${student.major}"></td>
                    <td class="actions">
                        <a th:href="@{/students/edit/{id}(id=${student.id})}">编辑</a>
                        <form th:action="@{/students/delete/{id}(id=${student.id})}" method="post" class="delete-form">
                            <button type="submit" onclick="return confirm('确定要删除此学生吗？');">删除</button>
                        </form>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</body>
</html> 